/**
 * Copyright 2017 wshunli
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.basemap.GZtianditu;

import android.content.Context;

import com.basemap.api.BaseMapApi;
import com.basemap.api.MapApi;
import com.esri.arcgisruntime.arcgisservices.TileInfo;
import com.esri.arcgisruntime.geometry.Envelope;

public class GZTianDiTuLayerBuilder {
    private int layerType = 0;
    private String cachePath = null;
    private String token = null;
    private String type = null;
    private Context context;

    public GZTianDiTuLayerBuilder setLayerType(int layerType) {
        this.layerType = layerType;
        return this;
    }

    public GZTianDiTuLayerBuilder setCachePath(String cachePath) {
        this.cachePath = cachePath;
        return this;
    }

    public GZTianDiTuLayerBuilder setToken(String token) {
        this.token = token;
        return this;
    }

    public GZTianDiTuLayerBuilder setType(String type) {
        this.type = type;
        return this;
    }

    public GZTianDiTuLayerBuilder setContext(Context context) {
        this.context = context;
        return this;
    }

    public GZTianDiTuLayer build() {
        GZTianDiTuLayerInfo layerInfo = GZLayerInfoFactory.getLayerInfo(layerType);
        TileInfo tileInfo = layerInfo.getTileInfo();
        Envelope fullExtent = layerInfo.getFullExtent();
        GZTianDiTuLayer tianDiTuLayer = new GZTianDiTuLayer(tileInfo, fullExtent);
        tianDiTuLayer.setLayerType(layerType);
        tianDiTuLayer.setCachePath(cachePath);
        token = "b1b55f2720244fd6b6c2ba46a3f3a6be";
        if (MapApi.gzTdtTK != null) {
            token = MapApi.gzTdtTK;
        }
        tianDiTuLayer.setToken(token);
        tianDiTuLayer.setType(type);
        tianDiTuLayer.setContext(context);
        return tianDiTuLayer;
    }
}
